package com.ljh.account.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ljh.account.dao.Announcement;
import com.ljh.account.dao.Resp.ExpenseResp;
import com.ljh.account.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    public void createAnnouncement(Announcement announcement) {
        announcementMapper.insertAnnouncement(announcement);
    }

    public void updateAnnouncement(Announcement announcement) {
        announcementMapper.updateAnnouncement(announcement);
    }

    public void deleteAnnouncement(Integer id) {
        announcementMapper.deleteAnnouncement(id);
    }

    public Announcement getAnnouncementById(Integer id) {
        return announcementMapper.selectAnnouncementById(id);
    }

    public PageInfo getAllAnnouncements(int page,int size) {
        PageHelper.startPage(page, size);
        List<Announcement> list = announcementMapper.selectAllAnnouncements();
        return new PageInfo(list);
    }

    public List<Announcement> getAnnouncementsByDateRange(Date startDate, Date endDate) {
        return announcementMapper.selectAnnouncementsByDateRange(startDate, endDate);
    }
}
